import Cookies from 'js-cookie'
const KEY = 'PIECE_SESSIONID'

export function getStorage(key) {
  return localStorage.getItem(key) || Cookies.get(key)
}

export function setStorage(key, value) {
  Cookies.set(key, value)
  return localStorage.setItem(key, value)
}

export function getAuthentication() {
  return localStorage.getItem(KEY) || Cookies.get(KEY)
}

export function setAuthentication(token) {
  return localStorage.setItem(KEY, token)
}

export function removeAuthentication() {
  Cookies.remove(KEY)
  return localStorage.removeItem(KEY)
}

export function getAuthenticationHeader() {
  return {
    'TenantHeader': 'Basic cGllY2UtdnVlLXNlcnZpY2U6cGllY2UtdnVl',
    'Authorization': 'Bearer ' + localStorage.getItem(KEY) || Cookies.get(KEY)
  }
}
